﻿using System;
using System.Collections.Generic;
using System.IO;
using Terraria.Localization;
using Terraria.ModLoader.IO;

namespace Terraria.ModLoader.Default
{
	// Token: 0x020002FF RID: 767
	public class MysteryItem : ModItem
	{
		// Token: 0x170001EA RID: 490
		// (get) Token: 0x06001D42 RID: 7490 RVA: 0x00014B41 File Offset: 0x00012D41
		public override string Texture
		{
			get
			{
				return "ModLoader/MysteryItem";
			}
		}

		// Token: 0x06001D43 RID: 7491 RVA: 0x00014B48 File Offset: 0x00012D48
		public override void SetStaticDefaults()
		{
			base.DisplayName.SetDefault("{$tModLoader.UnloadedItemItemName}");
			base.Tooltip.SetDefault("\n");
		}

		// Token: 0x06001D44 RID: 7492 RVA: 0x00014B6A File Offset: 0x00012D6A
		public override void SetDefaults()
		{
			base.item.width = 20;
			base.item.height = 20;
			base.item.rare = 1;
		}

		// Token: 0x06001D45 RID: 7493 RVA: 0x00014B92 File Offset: 0x00012D92
		internal void Setup(TagCompound tag)
		{
			this.modName = tag.GetString("mod");
			this.itemName = tag.GetString("name");
			this.data = tag;
		}

		// Token: 0x06001D46 RID: 7494 RVA: 0x00438B84 File Offset: 0x00436D84
		public override void ModifyTooltips(List<TooltipLine> tooltips)
		{
			for (int i = 0; i < tooltips.Count; i++)
			{
				if (tooltips[i].Name == "Tooltip0")
				{
					tooltips[i].text = Language.GetTextValue("tModLoader.UnloadedItemModTooltip", this.modName);
				}
				else if (tooltips[i].Name == "Tooltip1")
				{
					tooltips[i].text = Language.GetTextValue("tModLoader.UnloadedItemItemNameTooltip", this.itemName);
				}
			}
		}

		// Token: 0x06001D47 RID: 7495 RVA: 0x00014BBD File Offset: 0x00012DBD
		public override TagCompound Save()
		{
			return this.data;
		}

		// Token: 0x06001D48 RID: 7496 RVA: 0x00438C0C File Offset: 0x00436E0C
		public override void Load(TagCompound tag)
		{
			this.Setup(tag);
			Mod mod = ModLoader.GetMod(this.modName);
			int num = (mod != null) ? mod.ItemType(this.itemName) : 0;
			if (num > 0)
			{
				base.item.netDefaults(num);
				base.item.modItem.Load(tag.GetCompound("data"));
				ItemIO.LoadGlobals(base.item, tag.GetList<TagCompound>("globalData"));
			}
		}

		// Token: 0x06001D49 RID: 7497 RVA: 0x00438C80 File Offset: 0x00436E80
		public override void LoadLegacy(BinaryReader reader)
		{
			string text = reader.ReadString();
			bool flag = false;
			if (text.Length == 0)
			{
				flag = true;
				text = reader.ReadString();
			}
			TagCompound tagCompound = new TagCompound();
			tagCompound["mod"] = text;
			tagCompound["name"] = reader.ReadString();
			tagCompound["hasGlobalSaving"] = flag;
			tagCompound["legacyData"] = ItemIO.LegacyModData(int.MaxValue, reader, flag);
			this.Load(tagCompound);
		}

		// Token: 0x06001D4A RID: 7498 RVA: 0x00014BC5 File Offset: 0x00012DC5
		public override void NetSend(BinaryWriter writer)
		{
			TagIO.Write(this.data ?? new TagCompound(), writer);
		}

		// Token: 0x06001D4B RID: 7499 RVA: 0x00014BDC File Offset: 0x00012DDC
		public override void NetRecieve(BinaryReader reader)
		{
			this.data = TagIO.Read(reader);
			this.modName = this.data.GetString("mod");
			this.itemName = this.data.GetString("name");
		}

		// Token: 0x170001EB RID: 491
		// (get) Token: 0x06001D4C RID: 7500 RVA: 0x00008CF7 File Offset: 0x00006EF7
		public override bool CloneNewInstances
		{
			get
			{
				return true;
			}
		}

		// Token: 0x06001D4D RID: 7501 RVA: 0x00438CF8 File Offset: 0x00436EF8
		public override ModItem Clone()
		{
			MysteryItem mysteryItem = (MysteryItem)base.Clone();
			MysteryItem mysteryItem2 = mysteryItem;
			TagCompound tagCompound = this.data;
			mysteryItem2.data = (TagCompound)((tagCompound != null) ? tagCompound.Clone() : null);
			return mysteryItem;
		}

		// Token: 0x040018EC RID: 6380
		private string modName;

		// Token: 0x040018ED RID: 6381
		private string itemName;

		// Token: 0x040018EE RID: 6382
		private TagCompound data;
	}
}
